/***************************************************************************
 *   Copyright (C) 2007 by Anders Nore 																		 *
 *   andenore@start.no   																									 *
 *                                                                         *
 *   Permission is hereby granted, free of charge, to any person obtaining *
 *   a copy of this software and associated documentation files (the       *
 *   "Software"), to deal in the Software without restriction, including   *
 *   without limitation the rights to use, copy, modify, merge, publish,   *
 *   distribute, sublicense, and/or sell copies of the Software, and to    *
 *   permit persons to whom the Software is furnished to do so, subject to *
 *   the following conditions:                                             *
 *                                                                         *
 *   The above copyright notice and this permission notice shall be        *
 *   included in all copies or substantial portions of the Software.       *
 *                                                                         *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
 ***************************************************************************/

#ifndef __MCASTCHAT_H
#define __MCASTCHAT_H

#include <ncurses.h>
#include "config.h"
#include <sys/types.h>

/** CONSTANTS */
#define MAX_COMMANDNAME_LEN 8
#define MAX_ARGS_LEN 256
#define MAX_ARGS 256
#define MAX_GROUP_JOINS 20
#define INADDR_NAMELEN 16
#define SEPERATOR 0x20

#define MAGIC_NUM 0x73311337
#define SERV_PORT 5665
#define MAX_LINE 76
#define MAX_HISTORY 10
#define DEFAULT_MULTICAST_ADDR "224.0.0.5"


/** DEBUG MACROS */
#ifdef DEBUG

#define DEBUG_PRINT(dbug_str) \
	wprintw(mainwin, "DEBUG: " dbug_str "\n"); \
	wrefresh(mainwin)
		
#define DEBUG_PRINT_INT(dbug_str, dbug_int) \
	wprintw(mainwin, "DEBUG: " dbug_str " %i\n", dbug_int); \
	wrefresh(mainwin)
	
#define DEBUG_PRINT_STR(dbug_str, dbug_str2) \
	wprintw(mainwin, "DEBUG: " dbug_str " %s\n", dbug_str2); \
	wrefresh(mainwin)
	
#define DEBUG_PRINT_HEX(dbug_str, hex) \
	wprintw(mainwin, "DEBUG: " dbug_str " %x\n", hex); \
	wrefresh(mainwin)
	
#else

#define DEBUG_PRINT(dbug_str) //debug
#define DEBUG_PRINT_INT(dbug_str, dbug_int) //debug
#define DEBUG_PRINT_STR(dbug_str, dbug_str2) // debug
#define DEBUG_PRINT_HEX(dbug_str, hex) // debug

#endif

/** GLOBALS */
extern WINDOW *mainwin;
extern WINDOW *chatbar;
extern int sockfd;
extern char *str_interface_name, *str_multicast_addr;
extern int enable_colors;
 
 typedef int command_t(void *);		/* command function */ 

 /* Command switch table */
struct commandsw {	
	char com_name[MAX_COMMANDNAME_LEN];			/* commandstring to search for */
	int (*com_func)(void *);	/* function to execture for given command */
};
 
struct packetheader {
	uint32_t magicnum;
	char message[MAX_LINE];
};

 /* Commands */
#define CMD_NOCOMMAND 0
#define CMD_COMMAND 1
 
/**
 * checkInput checks our input from stdin for various commands 
 * and calls them, otherwise sends message to default multicastgroup.
 * @param inputbuf input textbuffer (standard input)
 * @return CMD_NOCOMMAND or CMD_COMMAND
 */
 int checkInput(char *);
 
#endif /* __MCASTCHAT_H */

